package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.FeedManage;
import com.ruoyi.system.service.IFeedManageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 饲料管理Controller
 * 
 * @author fxk
 * @date 2023-06-20
 */
@RestController
@RequestMapping("/system/feed_manage")
public class FeedManageController extends BaseController
{
    @Autowired
    private IFeedManageService feedManageService;

    /**
     * 查询饲料管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:feed_manage:list')")
    @GetMapping("/list")
    public TableDataInfo list(FeedManage feedManage)
    {
        startPage();
        List<FeedManage> list = feedManageService.selectFeedManageList(feedManage);
        return getDataTable(list);
    }

    /**
     * 导出饲料管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:feed_manage:export')")
    @Log(title = "饲料管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FeedManage feedManage)
    {
        List<FeedManage> list = feedManageService.selectFeedManageList(feedManage);
        ExcelUtil<FeedManage> util = new ExcelUtil<FeedManage>(FeedManage.class);
        util.exportExcel(response, list, "饲料管理数据");
    }

    /**
     * 获取饲料管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:feed_manage:query')")
    @GetMapping(value = "/{feedId}")
    public AjaxResult getInfo(@PathVariable("feedId") Integer feedId)
    {
        return success(feedManageService.selectFeedManageByFeedId(feedId));
    }

    /**
     * 新增饲料管理
     */
    @PreAuthorize("@ss.hasPermi('system:feed_manage:add')")
    @Log(title = "饲料管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FeedManage feedManage)
    {
        return toAjax(feedManageService.insertFeedManage(feedManage));
    }

    /**
     * 修改饲料管理
     */
    @PreAuthorize("@ss.hasPermi('system:feed_manage:edit')")
    @Log(title = "饲料管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FeedManage feedManage)
    {
        return toAjax(feedManageService.updateFeedManage(feedManage));
    }

    /**
     * 删除饲料管理
     */
    @PreAuthorize("@ss.hasPermi('system:feed_manage:remove')")
    @Log(title = "饲料管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{feedIds}")
    public AjaxResult remove(@PathVariable Integer[] feedIds)
    {
        return toAjax(feedManageService.deleteFeedManageByFeedIds(feedIds));
    }
}
